const localData = JSON.parse(localStorage.getItem("setting") || "{}");

const initialState = {
    theme: localStorage.getItem("theme") || "light", // 默认主题
    icon: "light",

    layout: localData.layout || "left", // 布局设置  可选值 ["left","top","mix"]
    color_weak: localData.color_weak !== undefined ? localData.color_weak : false, // 色弱模式
    color_gray: localData.color_gray !== undefined ? localData.color_gray : false, // 黑背模式
    color_primary: localData.color_primary || "#1677FF", // 主题色
    show_logo: localData.show_logo !== undefined ? localData.show_logo : true, // 显示logo 
    show_top_progress: localData.show_top_progress !== undefined ? localData.show_top_progress : false, // 显示顶部进度条
    show_multi_tab: localData.show_multi_tab !== undefined ? localData.show_multi_tab : true, // 显示多标签页
    show_footer: localData.show_footer !== undefined ? localData.show_footer : true, // 显示页脚版权信息
    show_breadcrumb: localData.show_breadcrumb !== undefined ? localData.show_breadcrumb : false, // 显示面包屑
    show_breadcrumb_icon: localData.show_breadcrumb_icon !== undefined ? localData.show_breadcrumb_icon : false, // 显示面包屑图标
    show_watermark: localData.show_watermark !== undefined ? localData.show_watermark : false, // 显示水印
    themes: localData.themes || {
        type: "light", // 默认主题
        icon: "light"
    }
};


interface actionProps {
    type: string;
    payload?: any;
}

const settingReducer = (state = initialState, action: actionProps) => {
    switch (action.type) {
        case 'TOGGLE_LAYOUT':
            return {
                ...state,
                layout: action.payload,
            };
        case 'TOGGLE_WEAK':
            return {
                ...state,
                color_weak: action.payload,
            };
        case 'TOGGLE_GRAY':
            return {
                ...state,
                color_gray: action.payload,
            };
        case 'TOGGLE_PRIMARY':
            return {
                ...state,
                color_primary: action.payload,
            };
        case 'TOGGLE_SHOWLOGO':
            return {
                ...state,
                show_logo: action.payload,
            };
        case 'TOGGLE_TOPPRPGRESS':
            return {
                ...state,
                show_top_progress: action.payload,
            };
        case 'TOGGLE_MULTITAB':
            return {
                ...state,
                show_multi_tab: action.payload,
            };
        case 'TOGGLE_FOOTER':
            return {
                ...state,
                show_footer: action.payload,
            };
        case 'TOGGLE_BREADCRUMB':
            return {
                ...state,
                show_breadcrumb: action.payload,
            };
        case 'TOGGLE_BREADCRUMBICON':
            return {
                ...state,
                show_breadcrumb_icon: action.payload,
            };
        case 'TOGGLE_WATERMARK':
            return {
                ...state,
                show_watermark: action.payload,
            };
        case 'TOGGLE_THEMES':
            return {
                ...state,
                themes: action.payload,
            };
        default:
            return state;
    }
};

export default settingReducer;
